import { createRouter, createWebHistory } from 'vue-router'
import LoginView from '@/views/login.vue'
import Layout from '@/layout/index.vue'
import Current from '@/views/works/Current.vue'
import Already from '@/views/works/Already.vue'
import BaseTab from '@/views/tabs/BaseTab.vue'

export const constantRoutes = [
  {
    path: '',
    component: Layout,
    redirect: '/index',
    children: [
      {
        path: '/index',
        component: Current,
        name: 'Index',
        meta: { title: '当前工作', icon: 'dashboard', affix: true }
      },
      {
        path: '/already',
        component: Already,
        meta: { title: '已完成工作', icon: 'dashboard', affix: true }
      },
      {
        name: 'transaction',
        path: '/transaction/:title/:typebCode/:transactionId',
        component: BaseTab,
        props: true,
        meta: { title: '', icon: 'dashboard', affix: false }
      }
    ]
  },
  {
    path: '/login',
    name: 'login',
    component: LoginView
  },
  {
    path: '/401',
    component: () => import('@/views/error/401.vue')
  },
  {
    path: '/:pathMatch(.*)*',
    component: () => import('@/views/error/404.vue')
  }
]

const router = createRouter({
  history: createWebHistory(),
  routes: constantRoutes,
  scrollBehavior(to, from, savedPosition) {
    if (savedPosition) {
      return savedPosition
    } else {
      return { top: 0 }
    }
  }
})

export default router
